/*
 * @Descripttion:
 * @Author: xiao li
 * @Date: 2020-07-06 12:17:06
 * @LastEditors: xiao li
 * @LastEditTime: 2021-06-03 14:32:55
 */
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import i18n from './i18n' // 语言包
import store from './store'
import router from './router'
import {
  api
} from './api' // 接口
import routes from './permission'
import util from './utils/public'
import Print from './utils/print'
import './components/basics'
import Nprogress from 'nprogress'
import vuescroll from 'vuescroll'
import '../static/Ueditor/ueditor.config.js'
import '../static/Ueditor/ueditor.all.js'
import '../static/Ueditor/lang/zh-cn/zh-cn.js'

import VueClipboard from 'vue-clipboard2'

Vue.use(VueClipboard)
Vue.use(vuescroll)

Vue.config.productionTip = false
Vue.use(Print)
Vue.prototype.$api = api
Vue.prototype.$util = util

router.beforeEach((to, from, next) => {
  Nprogress.start()
  if (to.path === '/login') {
    window.sessionStorage.removeItem('minitk')
    window.sessionStorage.removeItem('ms_username')
    next()
  } else if (!store.getters.isAuth) {
    api.getIsWeiVersion().then(res => {
      if (res.code === 200) {
        store.dispatch('isWeiVersion', res.data)
        if (!window.sessionStorage.getItem('minitk') && !res.data) {
          next('/login')
        } else {
          store.dispatch('getUserPromission', {
            to,
            next,
            routes
          })
        }
      }
    })
  } else {
    next()
  }
})
router.afterEach(() => {
  Nprogress.done()
})

/* eslint-disable no-new */
let vue = new Vue({
  el: '#app',
  router,
  i18n,
  store,
  components: {
    App
  },
  template: '<App/>'
})
export default vue
